from django.db import models

# Create your models here.

# 会员模型
class Users(models.Model):
    username = models.CharField(max_length=50)
    password = models.CharField(max_length=77)
    email = models.CharField(max_length=100,null=True)
    phone = models.CharField(max_length=11,null=True)
    sex = models.CharField(max_length=1,null=True)
    age = models.IntegerField(null=True)
    picurl = models.CharField(max_length=100,default='/static/pics/default/default.jpg')
    #0 正常 1禁用
    status = models.IntegerField(default=0)
    addtime = models.DateTimeField(auto_now_add=True)


# 商品分类模型
class Types(models.Model):
    name = models.CharField(max_length=50)
    pid = models.IntegerField()
    # path为层级路径
    path = models.CharField(max_length=50)

    def __str__(self):
        return '<Types: Types ' + self.name + '>'

# 商品模型
class Goods(models.Model):
    #商品所属分类 外键 多个商品对应一个分类
    typeid = models.ForeignKey(to='Types',to_field='id')
    title = models.CharField(max_length=50)
    price = models.DecimalField(max_digits=10,decimal_places=2)
    #商品库存
    storage = models.IntegerField()
    pic = models.CharField(max_length=50)
    info = models.TextField()
    #销量
    num = models.IntegerField(default=0)
    #浏览量
    pv = models.IntegerField(default=0)
    #商品状态:1 新品  2:热销  3:下架
    status = models.IntegerField(default=1)
    addtime = models.DateTimeField(auto_now_add=True)


# 会员收货地址 模型
class Address(models.Model):
    # 用户id
    uid = models.ForeignKey(to='Users',to_field='id')
    # 收货人
    addname = models.CharField(max_length=20)
    adds = models.CharField(max_length=255)
    addphone = models.CharField(max_length=11)
    # 是否是默认 默认1
    status = models.IntegerField(default=0)


# 订单表 ---订单详情
class Order(models.Model):
    uid = models.ForeignKey('Users',to_field='id')
    address = models.ForeignKey('Address',to_field='id')
    # 总价
    totalprice = models.IntegerField()
    totalnum = models.IntegerField()
    # 1未付款 2 已付款待发货 3已发货 4已完成
    status = models.IntegerField()
    addtime = models.DateTimeField(auto_now_add=Types)


# 订单详情
class OrderInfo(models.Model):
    # 多个详情对应一个订单
    orderid = models.ForeignKey('Order',to_field='id')
    # 一个商品多次下单 会有多个详情.
    gid = models.ForeignKey('Goods',to_field='id')
    #商品数量
    num = models.IntegerField()
    # 单价
    price = models.FloatField()

